/*
 * @Author: bothlent xwyin@bothlent.com
 * @Date: 2023-08-26 16:53:22
 * @LastEditors: bothlent xwyin@bothlent.com
 * @LastEditTime: 2023-08-27 18:56:23
 * @FilePath: /proejct_local_asr_wu_xin/src/util/util.cpp
 * @Description: 
 * 
 * Copyright (c) 2023 by bothelent, All Rights Reserved. 
 */
#define TAG "UTIL"
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../logger/log.h"

#define USB_CARD_NAME ("Bothlent UAC Dongle")

int get_usb_card_num(){
    system("arecord -l >./tmp.txt");
	FILE *file = fopen("./tmp.txt","r");
	if (file)
	{
		char buffer[200] = {0};
		while (!feof(file))
		{
			fgets(buffer , sizeof(buffer), file);

			if ( strstr(buffer , USB_CARD_NAME ) )
			{
                char card[10] = {0} ;
                strncpy(card , buffer+strlen("card "), 1);
                LOGD("find usb card number = %s" ,card);
                return atoi(card);
			}
			memset(buffer , 0 , sizeof(buffer));
		}
	}
    return -1 ;
}